|
mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
|
#include "common.h"
Go to the source code of this file.
Classes | |
| struct | mrb_shared_array |
| struct | RArray |
Macros | |
| #define | MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value))) |
| #define | mrb_ary_ptr(v) |
| #define | mrb_ary_value(p) |
| #define | RARRAY(v) |
| #define | MRB_ARY_EMBED_MASK 7 |
| #define | ARY_EMBED_P(a) |
| #define | ARY_UNSET_EMBED_FLAG(a) |
| #define | ARY_EMBED_LEN(a) |
| #define | ARY_SET_EMBED_LEN(a, len) |
| #define | ARY_EMBED_PTR(a) |
| #define | ARY_LEN(a) |
| #define | ARY_PTR(a) |
| #define | RARRAY_LEN(a) |
| #define | RARRAY_PTR(a) |
| #define | RARRAY_GETMEM(a, ptr, len) |
| #define | ARY_SET_LEN(a, n) |
| #define | ARY_CAPA(a) |
| #define | MRB_ARY_SHARED 256 |
| #define | ARY_SHARED_P(a) |
| #define | ARY_SET_SHARED_FLAG(a) |
| #define | ARY_UNSET_SHARED_FLAG(a) |
| #define | ARY_GETMEM(a, ptr, len) |
| #define | mrb_ary_ref(mrb, ary, n) |
Typedefs | |
| typedef struct mrb_shared_array | mrb_shared_array |
Functions | |
| mrb_static_assert (((mrb_int)(sizeof(void *) *3/sizeof(mrb_value))) > 0, "MRB_ARY_EMBED_LEN_MAX > 0") | |
| void | mrb_ary_modify (mrb_state *, struct RArray *) |
| Prepares an array for modification. | |
| mrb_value | mrb_ary_dup (mrb_state *, mrb_value ary) |
| mrb_value | mrb_ary_make_shared_copy (mrb_state *, mrb_value ary) |
| mrb_value | mrb_ary_new_capa (mrb_state *, mrb_int) |
| Creates a new array with a specified initial capacity. | |
| mrb_value | mrb_ary_new (mrb_state *mrb) |
| Creates a new, empty array. | |
| mrb_value | mrb_ary_new_from_values (mrb_state *mrb, mrb_int size, const mrb_value *vals) |
| Creates a new array initialized with a given sequence of values. | |
| mrb_value | mrb_assoc_new (mrb_state *mrb, mrb_value car, mrb_value cdr) |
| Creates a new array of size 2, typically used to represent an association (key-value pair). | |
| void | mrb_ary_concat (mrb_state *mrb, mrb_value self, mrb_value other) |
| Concatenates one array to another. | |
| mrb_value | mrb_ary_splat (mrb_state *mrb, mrb_value value) |
| Creates a new array from a given value, performing a "splat" operation. | |
| void | mrb_ary_push (mrb_state *mrb, mrb_value array, mrb_value value) |
| Pushes an element onto the end of an array. | |
| mrb_value | mrb_ary_pop (mrb_state *mrb, mrb_value ary) |
| Removes and returns the last element from an array. | |
| void | mrb_ary_set (mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val) |
| Sets the element at a given index in an array. | |
| void | mrb_ary_replace (mrb_state *mrb, mrb_value self, mrb_value other) |
| Replaces the contents of an array with the contents of another array. | |
| mrb_value | mrb_ary_unshift (mrb_state *mrb, mrb_value self, mrb_value item) |
| Prepends an element to the beginning of an array. | |
| mrb_value | mrb_ary_entry (mrb_value ary, mrb_int offset) |
| Retrieves an element from an array at a specific index. | |
| mrb_value | mrb_ary_splice (mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl) |
| Replaces a portion of an array with elements from another array or a single value. | |
| mrb_value | mrb_ary_shift (mrb_state *mrb, mrb_value self) |
| Removes and returns the first element from an array. | |
| mrb_value | mrb_ary_clear (mrb_state *mrb, mrb_value self) |
| Removes all elements from an array, making it empty. | |
| mrb_value | mrb_ary_join (mrb_state *mrb, mrb_value ary, mrb_value sep) |
| Joins the elements of an array into a string, separated by a given separator. | |
| mrb_value | mrb_ary_resize (mrb_state *mrb, mrb_value ary, mrb_int new_len) |
| Resizes an array to a new length. | |
See Copyright Notice in mruby.h
| #define ARY_CAPA | ( | a | ) |
| #define ARY_EMBED_LEN | ( | a | ) |
| #define ARY_EMBED_P | ( | a | ) |
| #define ARY_EMBED_PTR | ( | a | ) |
| #define ARY_GETMEM | ( | a, | |
| ptr, | |||
| len ) |
| #define ARY_LEN | ( | a | ) |
| #define ARY_PTR | ( | a | ) |
| #define ARY_SET_EMBED_LEN | ( | a, | |
| len ) |
| #define ARY_SET_LEN | ( | a, | |
| n ) |
| #define ARY_SET_SHARED_FLAG | ( | a | ) |
| #define ARY_SHARED_P | ( | a | ) |
| #define ARY_UNSET_EMBED_FLAG | ( | a | ) |
| #define ARY_UNSET_SHARED_FLAG | ( | a | ) |
| #define mrb_ary_ptr | ( | v | ) |
| #define mrb_ary_ref | ( | mrb, | |
| ary, | |||
| n ) |
| #define mrb_ary_value | ( | p | ) |
| #define RARRAY | ( | v | ) |
| #define RARRAY_GETMEM | ( | a, | |
| ptr, | |||
| len ) |
| #define RARRAY_LEN | ( | a | ) |
| #define RARRAY_PTR | ( | a | ) |
Retrieves an element from an array at a specific index.
This is a direct (unsafe) equivalent of RARRAY_PTR(ary)[n].
If n is negative, it counts from the end of the array. Returns nil if the index is out of bounds. This function does not perform a bounds check before accessing the element if the index is positive. Prefer using mrb_ary_ref for safe access or ensure n is within bounds.
| ary | The array (mrb_value) from which to retrieve the element. |
| n | The index of the element to retrieve. |
nil if out of bounds. Joins the elements of an array into a string, separated by a given separator.
Each element of ary is converted to a string. These strings are then concatenated, with the string representation of sep inserted between adjacent elements. If sep is nil, no separator is used. This function handles recursive array joins by raising an E_ARGUMENT_ERROR.
| mrb | The mruby state. |
| ary | The array (mrb_value) whose elements are to be joined. |
| sep | The separator (mrb_value) to use between elements. Can be nil. |
Prepares an array for modification.
This function ensures that the array is not frozen and is not shared. If the array is shared and has multiple references, this function will duplicate the array data to ensure that modifications do not affect other references. It also triggers a write barrier for the garbage collector.
| mrb | The mruby state. |
| a | A pointer to the RArray structure to modify. |
Creates a new, empty array.
This function is equivalent to calling mrb_ary_new_capa with a capacity of 0. The array will dynamically resize as elements are added.
| mrb | The mruby state. |
Creates a new array with a specified initial capacity.
This function allocates an array that can hold at least capa elements without needing to immediately reallocate memory. If capa is 0, it may still allocate a small default capacity.
| mrb | The mruby state. |
| capa | The initial capacity desired for the array. |
Creates a new array initialized with a given sequence of values.
This function allocates an array and copies size elements from the vals pointer into the new array.
| mrb | The mruby state. |
| size | The number of values to initialize the array with. |
| vals | A pointer to an array of mrb_values to copy into the new array. |
Removes and returns the last element from an array.
If the array is empty, returns nil. This function modifies the array in place.
| mrb | The mruby state. |
| ary | The array (mrb_value) from which to pop the element. |
nil if the array is empty. Pushes an element onto the end of an array.
This function appends elem to the ary array, increasing its length by one. The array capacity may be expanded if necessary. This function modifies the array in place.
Replaces the contents of an array with the contents of another array.
After this operation, the self array will contain the same elements as the other array. This function modifies the self array in place.
Resizes an array to a new length.
If new_len is smaller than the current length, the array is truncated. If new_len is larger than the current length, the array is expanded, and new elements are filled with nil. This function modifies the array in place.
| mrb | The mruby state. |
| ary | The array (mrb_value) to resize. |
| new_len | The desired new length of the array. |
ary). Sets the element at a given index in an array.
If n is within the current bounds of the array, the element at that index is replaced with val. If n is beyond the current bounds, the array is expanded to accommodate the new element, and any intermediate elements are filled with nil. If n is negative, it counts from the end of the array. An IndexError is raised if a negative index points past the beginning of the array. This function modifies the array in place.
Removes and returns the first element from an array.
If the array is empty, returns nil. All other elements are shifted down by one index. This function modifies the array in place.
| mrb | The mruby state. |
| self | The array (mrb_value) from which to shift the element. |
nil if the array is empty. Creates a new array from a given value, performing a "splat" operation.
If v is already an array, a duplicate of v is returned. If v responds to to_a, it is called, and if the result is an array, a duplicate of that result is returned. If to_a returns nil or something other than an array, v itself is wrapped in a new, single-element array. Otherwise (if v is not an array and does not respond to to_a), v itself is wrapped in a new, single-element array.
| mrb | The mruby state. |
| v | The mrb_value to convert into an array. |
|
extern |
Replaces a portion of an array with elements from another array or a single value.
Removes len elements from ary starting at head index, and inserts the elements from rpl (if rpl is an array) or rpl itself (if it's not an array) at that position. If head is negative, it counts from the end of the array. If len is negative, an IndexError is raised. If rpl is mrb_undef_p(), then the elements are removed without replacement. This function modifies the ary array in place.
| mrb | The mruby state. |
| ary | The array (mrb_value) to modify. |
| head | The starting index for the splice operation. |
| len | The number of elements to remove. |
| rpl | The mrb_value to insert (can be an array or a single value, or mrb_undef_p()). |
ary). Prepends an element to the beginning of an array.
This function adds item to the front of the self array, shifting all existing elements up by one index. The array capacity may be expanded if necessary. This function modifies the array in place.
| mrb | The mruby state. |
| self | The array (mrb_value) to unshift the element onto. |
| item | The mrb_value to prepend to the array. |
self). Creates a new array of size 2, typically used to represent an association (key-value pair).
The first element of the array is car (often the key), and the second element is cdr (often the value).
| mrb | The mruby state. |
| car | The first value to be placed in the array. |
| cdr | The second value to be placed in the array. |